﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using MpSoft.Library.BUSS.Products;
using MpSoft.Library.BUSS.Categories;
using MpSoft.Library.DTO;
using MpSoft.Basic.Utils;

namespace MpSoft.Web.Controls.Product
{
    public partial class ProductSellGood : System.Web.UI.UserControl
    {
        #region Method

        private void BindControl()
        {
            var list = ProductBUSS.Product_IsSellGood(-1, 9);
            rpList.DataSource = list;
            rpList.DataBind();
        }

        protected string GetCategoy(string categoryid)
        {
            if (!string.IsNullOrEmpty(categoryid))
            {
                var list = GetParent(int.Parse(categoryid));
                if (list.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    for (int i = list.Count - 1; i > -1; i--)
                        sb.Append("<a href='" + SEOHelper.GetCategoryUrl(list[i].SeName) + "'>" + list[i].CategoryName + "</a>");
                    return sb.ToString();
                }
            }
            return "";
        }

        private List<Category> GetParent(int parentid)
        {
            var obj = CategoryBUSS.Category_GetByID(parentid);
            List<Category> list = new List<Category>();
            while (obj != null)
            {
                list.Add(obj);
                obj = CategoryBUSS.Category_GetByID(obj.ParentID);
            }
            return list;
        }

        #endregion

        #region Event

        protected void Page_Load(object sender, EventArgs e)
        {
            BindControl();
        }

        #endregion
    }
}